clear all
set more off
	
global dir = "C:\Users\mrueda\Documents\Emory\Papers\Networks_persistance\do_files\do_files_APSA21\post_JOP\Replication_BJPS\"	

cd "$dir"

use "Data\cand_level_persist_rep.dta",clear

keep muni_code margin_victory fdonate_15any fb5

foreach var in donate_15any b5{
    rename  f`var' `var'
}

gen family=1

save  "Data\cand_level_persist_fam_aux_rep.dta",replace

use  "Data\cand_level_persist_rep.dta",clear

keep muni_code margin_victory nfdonate_15any nfb5

foreach var in donate_15any b5{
    rename  nf`var' `var'
}

gen family=0

append using "Data\cand_level_persist_fam_aux_rep.dta"


		
	gen treat=0
	replace treat=1 if margin_victory>0&margin_victory~=.
	replace treat=. if margin_victory==.

	gen treat_margin_victory=treat*margin_victory



	texdoc close 
	cap erase "$dir/Tables/TableF4.tex"
	texdoc init "$dir/Tables/TableF4.tex", force
	
	tex \begin{table}[tbph]
	tex \caption{Effect of donating to an election winner on future donations (candidate's family members and non-members, interaction global parametric linear RD)}\label{tab:donation_fam_nofam_inter_l}
	tex \centering
	tex \begin{tabular}{l c c } \hline
	tex Outcome : & Any race & Mayor  \\ 
	tex & (1) & (2)  \\ \hline
	tex & &  \\
	
	*Model 1
	foreach x in donate_15any b5{
			
		quietly: regress `x' (i.treat   c.treat_margin_victory c.margin_victory)##i.family, vce(cluster muni_code)
		quietly sum `x' if e(sample)
			local fmean_`x' : di %5.3f r(mean)
			local fsd_`x' : di %5.3f r(sd) 		
		
		regress `x' (i.treat   c.treat_margin_victory c.margin_victory)##i.family, vce(cluster muni_code)

		local fN_`x' : di %5.0f e(N)
		local fR2_`x' : di %5.3f e(r2)

		matrix b = e(b)
		matrix v = e(V)
		matrix res=r(table)
		
		local fb1_`x' : di %5.3f b[1,2]
		local fse1_`x' : di %5.3f sqrt(v[1,2])
		local fp_v1_`x' :di %5.3f res[4,2]
		local fuci1_`x': di %5.3f res[6,2]
		local flci1_`x': di %5.3f res[5,2]
		
		local fb2_`x' : di %5.3f b[1,10]
		local fse2_`x' : di %5.3f sqrt(v[1,10])
		local fp_v2_`x' :di %5.3f res[4,10]
		local fuci2_`x': di %5.3f res[6,10]
		local flci2_`x': di %5.3f res[5,10]

		lincom 1.treat+ 1.treat#1.family
		
		local fb3_`x': di %5.3f r(estimate)
		local fp_v3_`x' :di %5.3f r(p)
		local fuci3_`x': di %5.3f r(ub)
		local flci3_`x': di %5.3f r(lb)
		
	}
	
	*Continue table
	tex Electoral victory & `fb1_donate_15any' & `fb1_b5'  \\
	tex \ \ \ \ Robust p-value & `fp_v1_donate_15any' & `fp_v1_b5' \\
	tex \ \ \ \ CI 95\%  & [`flci1_donate_15any',`fuci1_donate_15any'] & [`flci1_b5',`fuci1_b5']  \\
	tex & &  \\
	
	tex Electoral victory $\times$ Family & `fb2_donate_15any' & `fb2_b5'  \\
	tex \ \ \ \ Robust p-value & `fp_v2_donate_15any' & `fp_v2_b5' \\
	tex \ \ \ \ CI 95\%  & [`flci2_donate_15any',`fuci2_donate_15any'] & [`flci2_b5',`fuci2_b5']  \\
	tex & &  \\ \hline
	
	tex Electoral victory (Family) & `fb3_donate_15any' & `fb3_b5'  \\
	tex \ \ \ \ Robust p-value & `fp_v3_donate_15any' & `fp_v3_b5' \\
	tex \ \ \ \ CI 95\%  & [`flci3_donate_15any',`fuci3_donate_15any'] & [`flci3_b5',`fuci3_b5']  \\
	tex & & \\ \hline
	
	tex Observations & `fN_donate_15any' & `fN_b5' \\
	tex Mean & `fmean_donate_15any' & `fmean_b5' \\ \hline
	tex \end{tabular}
	tex \parbox{160mm}{ \footnotesize{
	tex \footnotesize{OLS estimates of average treatment effects at cutoff. Controls include interaction of treatment with running variable and running variable. 95\% robust confidence intervals and p-values with clustering at the municipality level. 
	tex }
	tex }}
	tex \end{table}
	cap texdoc close 